#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

using namespace std;

bool iP(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }

    return true;
}

int nearestPrime(int n) {
    if (iP(n)) return n;

    int s = n - 1;
    int l = n + 1;

    while (true) {
        if (iP(s)) return s;
        if (iP(l)) return l;
        s--;
        l++;
    }
}

int main() {
    unordered_map<string, int> w = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    string a;
    getline(cin, a);

    int num = w[a.substr(0, 3)] * 100 + w[a.substr(4, 3)] * 10 +w[a.substr(8, 3)];
if (num <100 or num > 999) 
    cout << "Wrong input";

    cout << nearestPrime(num);
    return 0;
}